package org.price.sql.repo.documents.config;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

/**
 * Hello world!
 *
 */
public class Main {
    private static final Logger LOG = Logger.getLogger(Main.class);

    static {
        BasicConfigurator.configure();
    }

    public static void main(String[] args) throws Exception {
        Class.forName("org.postgresql.Driver");
        Connection conn = DriverManager.getConnection("jdbc:postgresql:gigi",
                "gigi", "gigi");

        LOG.info("Connected to :" + conn.getCatalog());
        LOG.info("Maximum statements: " + conn.getMetaData().getMaxStatements());
        LOG.info("Maximum connections: "
                + conn.getMetaData().getMaxConnections());
        LOG.info("Table name length: "
                + conn.getMetaData().getMaxTableNameLength());

        ExecutorService executor = Executors.newFixedThreadPool(10);

        // executor.execute(new CreateTablesThread(conn));

        for (int i = 0; i < 10000; i++) {
            executor.execute(new InsertThread(conn));
            executor.execute(new SelectThread(conn));
        }
        executor.shutdown();
    }
}
